﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CApMFFixtureConfigrationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPMODELLib;
using EMPTYPELIBRARYLib;
using EngineeringInternalExtension;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.ModularFixture;

internal class CApMFFixtureConfigrationValidator : ITxValidator
{
  private bool m_shouldIncludeConfig = true;
  private bool m_shouldIncludeBase = true;

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = "Invalid Object";
    bool flag = false;
    if (obj is TxPlanningObject planningObj && planningObj.IsDerivedFromPlanningType("UnitConfigurationPrototype") && this.IsValidType(planningObj))
    {
      flag = true;
      errorMessage = "";
    }
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = "Invalid Object";
    return false;
  }

  public ITxObject GetObject(string text) => (ITxObject) null;

  public string GetText(ITxObject obj) => TxObjectEx.GetPlanningObjectName(obj);

  private bool IsValidType(TxPlanningObject planningObj)
  {
    bool flag = false;
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    TxEmsServicesProvider servicesProvider = planningObj.PlatformServicesProvider as TxEmsServicesProvider;
    EmpFieldInfo field = ((IEmpObject) new EmpObjectClass()).GetField(ref empContext, ref new EmpObjectKey()
    {
      objectId = servicesProvider.InternalId
    }, "ConfigurationType");
    if (field.Value != null)
    {
      string str = (string) field.Value;
      if (this.ShouldIncludeBase && str.Equals("FixtureBase"))
        flag = true;
      else if (this.ShouldIncludeConfig && str.Equals("Configuration"))
        flag = true;
    }
    return flag;
  }

  internal bool ShouldIncludeConfig
  {
    set => this.m_shouldIncludeConfig = value;
    get => this.m_shouldIncludeConfig;
  }

  internal bool ShouldIncludeBase
  {
    set => this.m_shouldIncludeBase = value;
    get => this.m_shouldIncludeBase;
  }
}
